package com.myeasyexcel.controller;

import com.myeasyexcel.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author 作者
 * @create 2025-03-06 10:58
 */
@RestController
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;
    private final HttpServletResponse response;
    private final HttpServletRequest request;
    @PostMapping("/upload")
    public String upload(@RequestParam MultipartFile file,HttpServletResponse response) {
        userService.importExcel(file,  response);
        return "success";
    }

    @GetMapping("/export")
    public void export(HttpServletResponse response) {
        userService.export(response);
    }

    @GetMapping("/exportExcel")
    public void exportExcel(String param) {
        userService.exportExcel(param, response, request);
    }
}
